//
//  MYTabBarController.m
//  MYChatting
//
//  Created by mac on 16/7/15.
//  Copyright © 2016年 lhf. All rights reserved.
//

#import "MYTabBarController.h"
#import "MYHomeController.h"
#import "MYTabBar.h"
#import "MYBaseNavController.h"
#import "MYComposeController.h"

@interface MYTabBarController ()<MYTabBarDelegate>

@end

@implementation MYTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
#pragma mark 创建导航控制器的子控制器


//    UINavigationController *HomeNavc = [self loadViewControllerWithString:@"MYHomeController" andTitle:@"首页"andImageStr:@"tabbar_home" andImageSel:@"tabbar_home_highlighted"];
//    UINavigationController *MessageNavc = [self loadViewControllerWithString:@"MYMessageController" andTitle:@"信息" andImageStr:@"tabbar_message_center" andImageSel:@"tabbar_message_center_highlighted" ];
//    UINavigationController *DisCovNavc = [self loadViewControllerWithString:@"MYDiscoverController" andTitle:@"发现" andImageStr:@"tabbar_discover" andImageSel:@"tabbar_discover_highlighted"];
//    UINavigationController *ProNavc = [self loadViewControllerWithString:@"MYProfileController" andTitle:@"我" andImageStr:@"tabbar_profile" andImageSel:@"tabbar_profile_highlighted" ];
//    self.viewControllers = @[HomeNavc,MessageNavc,DisCovNavc,ProNavc];
    
    
    [self addChildViewController:[self loadViewControllerWithString:@"MYHomeController" andTitle:@"首页"andImageStr:@"tabbar_home" andImageSel:@"tabbar_home_highlighted"]];
    [self addChildViewController:[self loadViewControllerWithString:@"MYMessageController" andTitle:@"信息" andImageStr:@"tabbar_message_center" andImageSel:@"tabbar_message_center_highlighted" ]];
    [self addChildViewController:[self loadViewControllerWithString:@"MYDiscoverController" andTitle:@"发现" andImageStr:@"tabbar_discover" andImageSel:@"tabbar_discover_highlighted"]];
    [self addChildViewController:[self loadViewControllerWithString:@"MYProfileController" andTitle:@"我" andImageStr:@"tabbar_profile" andImageSel:@"tabbar_profile_highlighted" ]];
    
    
#pragma mark 自定义tabBar
 
    MYTabBar *tabBar = [[MYTabBar alloc] init];
    [tabBar.composeBtn addTarget:self action:@selector(composeBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self setValue:tabBar forKeyPath:@"tabBar"];

}



- (void)composeBtnClick{
   
    [self presentViewController:[[UINavigationController alloc] initWithRootViewController:[[MYComposeController alloc] init]] animated:YES completion:nil];
}


- (UINavigationController *)loadViewControllerWithString:(NSString *)string andTitle:(NSString *)title andImageStr:(NSString *)imgStr andImageSel:(NSString *)imageSelStr{
    Class MYClass = NSClassFromString(string);
    UIViewController *vc = [[MYClass alloc] init];
    vc.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:imgStr];
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0) {
        vc.tabBarItem.selectedImage = [[UIImage imageNamed:imageSelStr] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
   
    return [[MYBaseNavController alloc] initWithRootViewController:vc];
}
@end
